package com.galaxy.user.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.user.domain.UserAccount;
import com.galaxy.user.domain.UserBase;
import com.galaxy.user.domain.bo.UserAccountBo;
import com.galaxy.user.domain.vo.UserAccountVo;
import com.galaxy.user.service.UserAccountService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/account")
public class UserAccountApiController {

    private final UserAccountService userAccountService;

    @GetMapping("/list")
    public TableDataInfo<UserAccountVo> list(UserAccountBo bo, PageQuery pageQuery) {
        return userAccountService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/{id}")
    public R<UserAccount> getInfo(@PathVariable Long id) {
        return R.ok(userAccountService.queryById(id));
    }

    @GetMapping("/byUserId/{id}")
    public R<UserAccount> getInfoByUserId(@PathVariable Long id) {
        return R.ok(userAccountService.getInfoByUserId(id));
    }

    @PostMapping
    public R<Boolean> add(@RequestBody UserAccountBo bo) {
        return R.ok(userAccountService.insertByBo(bo));
    }

    @PutMapping
    public R<Boolean> edit(@RequestBody UserAccountBo bo) {
        return R.ok(userAccountService.updateByBo(bo));
    }

    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable List<Long> ids) {
        return R.ok(userAccountService.deleteWithValidByIds(ids, true));
    }

    @PutMapping("/updatePoints")
    public R<Boolean> updateAvatar(@RequestParam("userId")Long userId, @RequestParam("points") Integer points) {
        Boolean b = userAccountService.updateAvatar(userId, points);
        return R.ok(b);
    }

    @PutMapping("/updateBalance")
    public R<Boolean> updateBalance(@RequestParam("userId")Long userId, @RequestParam("balance") BigDecimal balance) {
        Boolean b = userAccountService.updateBalance(userId, balance);
        return R.ok(b);
    }

    @PutMapping("/updateBalance1")
    public R<Boolean> updateBalance1(@RequestParam("userId")Long userId, @RequestParam("balance") BigDecimal balance) {
        Boolean b = userAccountService.updateBalance1(userId, balance);
        return R.ok(b);
    }

    @PutMapping("/updatePoints1")
    public R<Boolean> updatePoints(@RequestParam("userId")Long userId, @RequestParam("points") Integer points) {
        Boolean b = userAccountService.updatePoints(userId, points);
        return R.ok(b);
    }
}
